package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * 增强型for循环
 */
public class NewForDemo {
    public static void main(String[] args) {
        String[] array = {"hello", "world", "java"};
        for(int i = 0; i < array.length; i++){
            System.out.println(array[i]);
        }

        //增强for循环方式
        for(String s : array){ //s 表示数组中的每个元素
            System.out.println(s);
        }

        System.out.println("------------------");

        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        Iterator<String> it = c.iterator();
        while(it.hasNext()){
            String s = it.next();
            System.out.println(s);
        }

        //增强for循环方式
        for(String s : c){
            System.out.println(s);
        }
    }
}
